﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Xml;
using System.Xml.XPath;
using System.Collections;

//AUI Model Component
using AdaptiveHelpDesk.AUI_Model_Components.Watcher.Combo_box;

namespace AdaptiveHelpDesk.AUI_Model_Components.Watcher.Combo_box.GetUserModel
{
    class GetUserModelComboBox
    {
        #region VARIABLES

            SqlConnection con = null;
            SqlDataReader rdr = null;
            XmlDocument doc;

            XmlElement InteractionFeatures;

            XmlElement LowlevelMotionCharact;

            XmlElement InteractionTechn;

            XmlElement PerformanceM;

            String UserID = "";
            String dateLogged = "";
            String timeLogged = "";


            LowLevelMotionCharacteristics classLowLevelMotionCharacteristics;
            InteractionTechnique classInteractionTechnique;
            PerformanceModels classPerformaceModel;

            String getStoredProcedureColumn = "";
            String getStoreProcedureName = "";
            String updateStoredProcedureColumn = "";
            String updateStoreProcedureName = "";

        #endregion



        #region INITIALISATION

            public GetUserModelComboBox(string UID, string dateL, string timeL, string getSPName, string getSPColumn, string updateSPName, string updateSPColumn)
            {

                UserID = UID;
                dateLogged = dateL;
                timeLogged = timeL;
                getStoredProcedureColumn = getSPColumn;
                getStoreProcedureName = getSPName;
                updateStoredProcedureColumn = updateSPColumn;
                updateStoreProcedureName = updateSPName;

                //Get the User Model for the specified INformative Moment
                this.getUserModelComboBoxXML(UID, dateL, timeL);

                classLowLevelMotionCharacteristics = new LowLevelMotionCharacteristics();
                classInteractionTechnique = new InteractionTechnique();
                classPerformaceModel = new PerformanceModels();

                InteractionFeatures = (XmlElement)doc.DocumentElement.FirstChild;

                //LowLevelMotionCharacteristics();

                //InteractionTechnique();

                //PerformanceModel();

            }

        #endregion



        #region OPEN CONNECTION

            private void openConnection()
            {
                con = new SqlConnection("Data Source=" + System.Environment.MachineName + ";Initial Catalog=ISD;Integrated Security=True");
                //con = new SqlConnection("Data Source=ROCABEE;Initial Catalog=ISD;Integrated Security=True");
                con.Open();
            }

            #endregion

        
    
        #region GET USER MODEL XML SO THAT IT CAN BE ANALYSED

                private XmlDocument getUserModelComboBoxXML(string UID, string dateLog, string timeLog)
                {
                    try
                    {
                        openConnection();
                        SqlCommand cmd = new SqlCommand(getStoreProcedureName, con);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add(new SqlParameter("@userID", UID));
                        cmd.Parameters.Add(new SqlParameter("@date", dateLog));
                        cmd.Parameters.Add(new SqlParameter("@time", timeLog));

                        rdr = cmd.ExecuteReader();
                        doc = new XmlDocument();
                        String XMLstring = "";

                        while (rdr.Read())
                        {
                            XMLstring = (String)rdr[getStoredProcedureColumn];
                        }

                        doc.LoadXml(XMLstring);

                        return doc;
                    }
                    finally
                    {
                        if (con != null)
                        {
                            con.Close();
                        }
                        if (rdr != null)
                        {
                            rdr.Close();
                        }
                    }
                }

            #endregion


    }
}
